Skip to main content

Overview

OpenCLIP supports two main data formats for training:
  1. CSV Format: Simple, good for small to medium datasets (<10M samples)
  2. WebDataset Format: Efficient, required for large-scale datasets (>10M samples)
This guide covers how to prepare, format, and optimize your training data.

CSV Format

CSV format is the simplest way to specify image-text pairs for training.

Basic CSV Structure

Create a CSV or TSV file with image paths and corresponding captions:

CSV Parameters

Control CSV parsing with these flags:
Parameters:
  • --csv-separator: Column delimiter (default: \t for tab)
  • --csv-img-key: Column name for image paths (default: filepath)
  • --csv-caption-key: Column name for captions (default: title)

CSV Format Examples

Tab-separated (default):
Comma-separated:
Custom columns:

CSV Best Practices

Good practices:
  • Use absolute paths for image files
  • Quote captions containing commas or special characters
  • Keep CSV files on fast storage (SSD)
  • Split large CSVs into train/val sets
Limitations:
  • CSV format is slow for datasets >10M samples
  • Random access is inefficient for shuffling
  • No built-in data sharding for distributed training
  • Recommendation: Use WebDataset for datasets >10M samples

Validation Data

Provide a separate CSV for validation:

WebDataset Format

WebDataset is a streaming dataset format optimized for large-scale training. It stores data in .tar archives with efficient sequential access.

WebDataset Structure

A WebDataset consists of multiple .tar files, each containing paired image and text files:
Key points:
  • Each sample consists of an image file and a text file with the same name
  • Files are grouped into .tar archives (typically 1,000-10,000 samples each)
  • Archives can be stored locally or accessed remotely (S3, HTTP)

Creating WebDatasets with img2dataset

img2dataset is the recommended tool for converting image-text datasets to WebDataset format.

Installation

Basic Usage

Input: Parquet or CSV file with image URLs and captions
Convert to WebDataset:
Output:

Conceptual Captions 3M Example

See the CC3M img2dataset example for a complete walkthrough:

Training with WebDataset

Use the --dataset-type webdataset flag:
Key parameters:
  • --train-data: Path with glob pattern for .tar files
  • --train-num-samples: Total number of samples (required)
  • --dataset-type webdataset: Specify WebDataset format

Glob Patterns for WebDataset

WebDataset supports bash-style glob patterns:

Dataset Resampling

For large datasets, enable sampling with replacement:
Benefits of --dataset-resampled:
  • Enables efficient epoch-based training on streaming datasets
  • Allows training for fewer than one full epoch (via --train-num-samples)
  • Required when using multiple data sources with upsampling

Partial Epochs for Large Datasets

For very large datasets (LAION-2B), train on a fraction of an epoch:

Multiple Data Sources

Combine multiple datasets using the :: separator:

Data Upsampling Factors

By default, samples from each source are proportional to dataset size. Use --train-data-upsampling-factors to control weighting:
Examples:

Combining LAION and CC12M Example

Remote Data Loading

WebDataset supports loading data from remote sources:

AWS S3

HTTP/HTTPS

Google Cloud Storage

Remote data loading requires network bandwidth. For best performance:
  • Use local storage when possible
  • Ensure high-bandwidth network connection
  • Monitor network utilization with iftop or nethogs

Data Format Specifications

Image Formats

Supported image formats:
  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • WebP (.webp)
  • Any format supported by PIL/Pillow
Recommendations:
  • Use JPEG for photographs (smaller file size)
  • Use PNG for images with transparency or text
  • Store at reasonable resolution (224-512px for most models)

Text Formats

WebDataset: Plain text files (.txt)
CSV: Quoted strings
Caption guidelines:
  • Keep captions concise but descriptive
  • Typical length: 5-20 words
  • Remove special characters that may cause parsing issues
  • Use UTF-8 encoding for international text

Data Quality Considerations

Image Quality

Good practices:
  • Filter out corrupted or unreadable images
  • Remove duplicates
  • Ensure minimum resolution (e.g., 224x224)
  • Verify aspect ratios are reasonable
  • Check for NSFW content if needed

Caption Quality

Good practices:
  • Remove empty or very short captions (<3 words)
  • Filter out captions with excessive special characters
  • Remove duplicate captions
  • Consider language filtering for multilingual datasets
  • Remove personally identifiable information (PII)

Dataset Size Recommendations

Example Datasets

Conceptual Captions 3M (CC3M)

Conceptual Captions 12M (CC12M)

LAION Datasets

LAION datasets are available as pre-processed WebDatasets: See LAION documentation for download instructions.

Preprocessing and Augmentation

Image Preprocessing

Images are automatically preprocessed during training:
  1. Resize to model input size (default: 224x224)
  2. Normalize with ImageNet statistics
  3. Data augmentation (optional)
Control preprocessing with these flags:

Data Augmentation

Custom augmentation via --aug-cfg:
See Configuration for all augmentation options.

Storage Optimization

Tar File Size

Recommended tar file sizes:
  • 1,000-10,000 samples per .tar for local storage
  • Smaller tars (1,000-5,000) for remote/networked storage
  • Balance between random access and I/O efficiency

Compression

WebDataset .tar files can be compressed:
Tradeoff: Smaller storage vs. CPU overhead for decompression

SSD vs HDD

Troubleshooting

Slow Data Loading

Symptom: Low GPU utilization (<80%) Solutions:
  1. Increase --workers (more data loading processes)
  2. Use faster storage (SSD instead of HDD)
  3. Convert CSV to WebDataset for large datasets
  4. Reduce image resolution in preprocessing
  5. Check network bandwidth for remote data

Corrupted Images

Symptom: Training crashes with PIL errors Solutions:
  1. Filter corrupted images during preprocessing:
  2. Add error handling in custom data pipeline
  3. Validate all images before creating WebDataset

Missing Files

Symptom: FileNotFoundError during training Solutions:
  1. Use absolute paths in CSV files
  2. Verify file permissions
  3. Check glob patterns for WebDataset
  4. Ensure all nodes have access to shared storage (multi-node)

Unbalanced Data Sources

Symptom: Model overfits to larger dataset Solutions:
  1. Use --train-data-upsampling-factors to balance sampling
  2. Create weighted mixture of datasets
  3. Train on larger dataset first, then fine-tune on smaller

Data Validation Script

Validate your WebDataset before training:

Next Steps

Single-Node Training

Train on prepared data with single machine

Configuration

Configure training parameters and data augmentation

Distributed Training

Optimize data loading for distributed training

Training Overview

Return to training overview